﻿//------------------------------------------------------------------------------
// <copyright file="TestTest.cs" company="CommerceServer.net, Inc">
//    (c) 2012 CommerceServer.net, Inc. and its affiliates. All rights reserved.
// </copyright>
// <summary></summary>
//------------------------------------------------------------------------------ 
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CommerceServer.Foundation;


namespace CommerceServerContrib.CodeGeneration.Test
{
    [TestClass]
    public class TestTest
    {
        /// <summary>
        /// Test to see if the basic configuration of the test project is working by talking to Commerce Server
        /// </summary>
        [TestMethod]
        public void BaseCommerceServerTest()
        {
            var simpleCatalogQuery = new CommerceQuery<CommerceEntity>("Catalog");
            simpleCatalogQuery.SearchCriteria.Model.Id = "Adventure Works Catalog";

            var response = this.Execute(simpleCatalogQuery);
        }

        #region Helpers I don't like
        /// <summary>
        /// Sample channel name.
        /// </summary>
        public const string Channel = "";

        /// <summary>
        /// Service agent instance.
        /// </summary>
        private OperationServiceAgent operationServiceAgent;

        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <returns>The response instance.</returns>
        public CommerceResponse Execute(CommerceBaseBuilder operation)
        {
            ParameterChecker.CheckForNull(operation, "operation");

            if (operationServiceAgent == null)
            {
                operationServiceAgent = new OperationServiceAgent();
            }

            return operationServiceAgent.ProcessRequest(
                GetCurrentRequestContext(), operation.ToRequest());
        }

        /// <summary>
        /// Gets the current request context.
        /// </summary>
        /// <returns>A request context instance.</returns>
        private  CommerceRequestContext GetCurrentRequestContext()
        {
            CommerceRequestContext requestContext = new CommerceRequestContext()
            {
                Channel = Channel,
                UserLocale = "en-US",
                UserUILocale = "en-US",
                RequestId = Guid.NewGuid().ToString()
            };

            return requestContext;
        }
        #endregion
    }
}
